﻿/*
 *for ocx : 
 *Version :
 */

//--------------------clientElements-------begin---------
var isOpenRcd = false; //录入页是否打开
var btns=new Array(1,1,1,1,1,1,1,1); //定义按钮的点击状态（1表示初始状态1；0表示初始状态2）

//显示或隐藏图片按钮和点击事件
function showImage(id,picsrc,enable,btnsstat) {
	var elementimg;//图片
	var elementa;//链接
	elementimg = document.getElementById(id);
	elementimg.src = picsrc;

	if (enable==0){
		//elementimg.className = "grayscale";//图片变灰
		elementa= document.getElementById(id + "a");
		elementa.style.cursor='default'; //改变鼠标形状
		elementa.onclick=''; //取消onclick事件 
	}
	else{
		//elementimg.className = "";	
		elementa= document.getElementById(id + "a");
		elementa.style.cursor='auto'; //改变鼠标形状
		elementa.onclick=function(){clickImage(id,btnsstat);}; //添加onclick事件 
	}
}

//--====根据状态控制按钮图片{---------
function cti_qianru() {
//登录/签入状态
	showImage("btn1","../ctiHW/qianchu03.jpg",1,1);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shixian02.jpg",0,0);//按钮3：示闲，示忙//enable???
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
	//btns[0]=0;//全局变量，初始状态
}
function cti_state0weidl() {
// 除签入按钮外屏蔽所有功能
	showImage("btn1","../ctiHW/qianru03.jpg",1,0);//按钮1：签入签出（当前状态为签出成功，显示按钮“签入”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shixian02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_state1kongxian() {
//当前状态为“示闲”,显示“示忙”按钮	
	// Enable： 签出、示忙、呼叫
	// Disable: 签入、接听、示闲、三方、转接	
	showImage("btn1","../ctiHW/qianchu03.jpg",1,1);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shimang03.jpg",1,1);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao03.jpg",1,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：呼叫
}
function cti_state2manglu() {
	// Enable： 签出、示闲、呼叫
	// Disable: 签入、接听、示忙、三方、转接
	showImage("btn1","../ctiHW/qianchu03.jpg",1,1);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shixian03.jpg",1,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao03.jpg",1,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_state3zhenlin() {
	// Enable: 接听 
	// Disable: 签入、签出、示忙、示闲、三方、转接、呼叫、挂机
	showImage("btn1","../ctiHW/qianru01.jpg",0,1);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting03.jpg",1,0);//按钮2：接听
	showImage("btn3","../ctiHW/shimang02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断（振铃的时候不能挂断。如果骚扰电话，用“黑名单”处理）
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_state4hujiao() {
	// Enable: 接听、挂机
	// Disable: 签入、签出、示忙、示闲、三方、转接、呼叫
	showImage("btn1","../ctiHW/qianru01.jpg",0,0);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting03.jpg",1,0);//按钮2：接听
	showImage("btn3","../ctiHW/shimang02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan03.jpg",1,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_state5tonghua(callDirection) {

	var transOrConference = 0;

	if(ctrl.TransferState != 0 || ctrl.ConferenceState != 0)
	{
		transOrConference = 1;
	}

	// Enable: 挂机、三方、转接
	// Disable: 签入、签出、接听、示忙、示闲、呼叫
	showImage("btn1","../ctiHW/qianru01.jpg",0,0);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,1);//按钮2：接听
	showImage("btn3","../ctiHW/shimang02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休

	showImage("btn5","../ctiHW/guaduan03.jpg",1,0);//按钮5：挂断
	//showImage("btn6","../ctiHW/sanfang01.jpg",transOrConference,0);//按钮6：三方，取消三方
	//showImage("btn7","../ctiHW/zhuanjie01.jpg",transOrConference,0);//按钮7：转接，取消转接

	if(transOrConference == 1)	{
		showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
		showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
		showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
	}
	else{
		showImage("btn6","../ctiHW/sanfang03.jpg",1,0);//按钮6：三方，取消三方
		showImage("btn7","../ctiHW/zhuanjie03.jpg",1,0);//按钮7：转接，取消转接


		if(ctrl.HeldCallInfo!=null)
		{
			showImage("btn9","../ctiHW/quxiao03.jpg",1,1);//按钮9：取消保持		
		}
		else
		{
			showImage("btn9","../ctiHW/baochi03.jpg",1,0);//按钮9：保持
		}
	}

	showImage("btn8","../ctiHW/hujiao02.jpg",0,1);//按钮8：呼叫
}
function cti_state6huahou() {
	// Enable: 签出、示闲、
	// Disable：签入、示忙、接听、三方、转接、挂机	
	showImage("btn1","../ctiHW/qianchu03.jpg",1,1);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shixian03.jpg",1,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu03.jpg",1,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_qianchu() {
//注销/签出状态
	// 除签入按钮外屏蔽所有功能
	showImage("btn1","../ctiHW/qianru03.jpg",1,0);//按钮1：签入签出（当前状态为签出成功，显示按钮“签入”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shixian02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫 
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_jieting() {
//有电话进来的时候 才能显示“接听”和“挂断”按钮
	showImage("btn1","../ctiHW/qianru01.jpg",0,0);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting03.jpg",1,0);//按钮2：接听
	showImage("btn3","../ctiHW/shimang02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan03.jpg",1,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_guaduan() {
//挂断电话
	//有电话进来的时候 才能显示“接听”按钮
	showImage("btn1","../ctiHW/qianru01.jpg",0,0);//按钮1：签入签出（当前状态为签出成功，显示按钮“签入”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shixian02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan01.jpg",1,0);//crt按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫 
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_shixian() {
//示闲
	showImage("btn3","../ctiHW/shixian01.jpg",1,0);//crt
}
function cti_shimang() {
//示忙
	showImage("btn3","../ctiHW/shimang01.jpg",1,1);//crt
}
function cti_jietingf() {
//不显示“接听”按钮
	window.document.getElementById("btn2").src = "../ctiHW/jieting02.jpg"; //接听(有电话进来的时候 才能显示“接听”按钮)
	window.document.getElementById("btn2a").style.cursor="default";
	window.document.getElementById("btn2a").onclick="";
	btns[1]=1;//全局变量，初始状态
}
function cti_sanfang() {
//正在进行三方通话
	showImage("btn6","../ctiHW/sanfang01.jpg",1,0);//crt
}
function cti_sanfangc() {
//没有进行三方通话操作("c"表示cancel)
	showImage("btn1","../ctiHW/qianchu03.jpg",0,0);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shimang02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfangqx01.jpg",1,1);//crt按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjie02.jpg",0,0);//按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
}
function cti_zhuanjie() {
//转接的第三方已经接通，等到确认
	showImage("btn7","../ctiHW/zhuanjie01.jpg",1,0);//crt
}
function cti_zhuanjiec() {
//没有进行转接操作("c"表示cancel)
	showImage("btn1","../ctiHW/qianchu03.jpg",0,0);//按钮1：签入签出（当前状态为签入成功，显示按钮“签出”）
	showImage("btn2","../ctiHW/jieting02.jpg",0,0);//按钮2：接听
	showImage("btn3","../ctiHW/shimang02.jpg",0,0);//按钮3：示闲，示忙
	showImage("btn4","../ctiHW/xiaoxiu02.jpg",0,0);//按钮4：小休
	showImage("btn5","../ctiHW/guaduan02.jpg",0,0);//按钮5：挂断
	showImage("btn6","../ctiHW/sanfang02.jpg",0,0);//按钮6：三方，取消三方
	showImage("btn7","../ctiHW/zhuanjieqx01.jpg",1,1);//crt按钮7：转接，取消转接
	showImage("btn8","../ctiHW/hujiao02.jpg",0,0);//按钮8：呼叫
}
function cti_hujiao() {
//外呼
	showImage("btn8","../ctiHW/hujiao01.jpg",1,0);//crt
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
function cti_hujiaoc() {
//外呼挂断
	showImage("btn8","../ctiHW/hujiao01.jpg",1,1);//crt
	showImage("btn9","../ctiHW/baochi02.jpg",0,0);//按钮9：保持
}
//--====根据状态控制按钮图片}---------

//点击图片
function clickImage(id,btnsstat){
	switch(id) {
		case "btn1"://按钮1：签入签出

			if (btnsstat==0){
				Login();
			}
			else {
				Logout();
			}
			break;
		case "btn2"://按钮2：接听
			if (btnsstat==0) {
				AnswerCall();//接听	
			}
			else{
				ReleaseCall();//挂断	
			}
			break;
		case "btn3"://按钮3：示闲，示忙
			if (btnsstat==0){
				SetReady();//示闲
			}
			else{
				SetNotReady();//示忙	
			}
			break;
		case "btn4"://按钮4：小休
			if (btnsstat==0){
				SetNotReady();//示忙	
			}
			else{
				;
			}
			break;
		case "btn5"://按钮5：挂断
			if (btnsstat==0){
				ReleaseCallEx();//挂断	
			}
			else{
				;
			}
			break;
		case "btn6"://按钮6：三方，取消三方
			if (btnsstat==0){
				//InitialConference();//初始化3方通话
				//CompleteConference();//完成3方通话
				window.showModalDialog("../ctiHW/ziConference.html",window,"dialogWidth:520px;dialogHeight:300px;help:no;scroll:no;status:no;");
			}
			else{
				CancelConference();//取消3方通话
			}
			break;
		case "btn7"://按钮7：转接，取消转接
			if (btnsstat==0) {
				//InitialTransfer();//初始化转接
				//CompleteTransfer();//完成转接
				window.showModalDialog("../ctiHW/ziTransfer.html",window,"dialogWidth:520px;dialogHeight:300px;help:no;scroll:no;status:no;");
			}
			else {
				CancelTransfer();//取消转接	
			}
			break;
		case "btn8"://按钮8：呼叫
			if (btnsstat==0){
				//CallAgent();//呼叫
				window.showModalDialog("../ctiHW/ziCallagent.html",window,"dialogWidth:520px;dialogHeight:300px;help:no;scroll:no;status:no;");
			}
			else {
				ReleaseCall();//挂断	
			}
			break;
		case "btn9"://按钮9：呼叫保持/取消保持
			if (btnsstat==0){
				try{
					var call = ctrl.ActiveCallInfo;
					if(call != null) {

						ctrl.HoldCall();
						showImage("btn9","../ctiHW/quxiao03.jpg",1,1);//按钮9：取消
//			    return;
					}
				}catch (e) {
					alert(e.message);
				}

			}else{
				try{
					var call = ctrl.HeldCallInfo;

					if(call !=null)
					{
						ctrl.RetrieveCall();
						showImage("btn9","../ctiHW/baochi03.jpg",1,0);//按钮9：保持
					}
				}catch (e) {
					alert(e.message);
				}
			}
			break;

		default:
			break;
	}
}
//--------------------clientElements-------end-----------

//--------------------CTI Base-------begin---------
function updateAgentStatusTime() {
	var seconds = ctrl.AgentStatusTime;//AgentStatusTime:只读属性，获取座席当前状态持续时长，单位为秒。
	var time = new Date(0, 0, 0, 0, 0, seconds);
	window.document.getElementById("ctiLasttime").innerHTML=time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
}
function updatePhoneNumber(){
	if(ctrl.ActiveCallInfo != null){

		window.document.getElementById("ctiCallphone").innerHTML = GetPhoneNumber(ctrl.ActiveCallInfo);
	}
	else if(ctrl.HeldCallInfo != null){
		window.document.getElementById("ctiCallphone").innerHTML = GetPhoneNumber(ctrl.HeldCallInfo);
	}
	else{
		window.document.getElementById("ctiCallphone").innerHTML = "";
	}
}

function AgentStatus()
{
	return ctrl.AgentStatus;
}

function TransferState(){
	return ctrl.TransferState;
}
function ConferenceState(){
	return ctrl.ConferenceState;
}

function SendDTMF(digits)
{
	ctrl.SendDTMF(digits);
}

function GetPhoneNumber(callInfo)
{
	if(!callInfo) return "";

	if(callInfo.CallDirection == 1)
	{
		return callInfo.CallerNum;
	}
	else if(callInfo.CallDirection == 2)
	{
		if(callInfo.CalledNum.substr(0,1) == '9')
		{
			return callInfo.CalledNum.substr(1);
		}

		return callInfo.CalledNum;
	}

	return "";
}

//登录
function Login() {
	try {
		ctrl.Login();
		//alert("Login");
	}
	catch(e) {
		alert(e.message);//如果在没有“初始化”的情况登录，弹出“数据库参数无效”，；登录成功后坐席状态显示“示闲”，
		//？？？登录不成功，弹出“登录超时”；再点登录，弹出“当前正在登录”
	}
}

// 注销
function Logout() {
	try {
		ctrl.Logout();
		//alert("Logout");
	}
	catch (e) {
		alert(e.message);  //如果未登录弹出“坐席未登陆”；注销成功后坐席状态显示“未登录”
	}
}

// 准备好(座席示闲)
function SetReady() {
	try {
		ctrl.SetReady();
		//alert("shi xian");
	}
	catch (e) {
		alert(e.message);
	}
}

// 未准备好(座席示忙)    示忙原因 1	-  小休;2	-  外出就餐;3	-  培训;4	-  会议;5	-  主动服务
function SetNotReady() {//130914 弹出“参数是必须的”
	try {
		ctrl.SetNotReady(1);//示忙原因 1	-  小休;
		//alert("shi mang");
	}
	catch (e) {
		alert(e.message);
	}
}

//呼叫(打出电话)
function CallAgentold() {
	try {
		var str = textNumber.value;
		if (str == null) {
			alert("请输入电话号码");
			return;
		}

		ctrl.MakeCall(str);
	}
	catch (e) {
		alert(e.message);
	}
}
//呼叫(打出电话)
function CallAgent(number) {

	try {
		ctrl.MakeCall("9"+number);
		//alert("打出电话"+number);
	}
	catch (e) {
		alert(e.message);
	}
}

//接听电话
function AnswerCall(){
	try {
		ctrl.AnswerCall();
		//alert("jieting");
	}
	catch (e) {
		alert(e.message);
	}
}

//保持电话（会播放音乐，测试：对话双方互相都听不到声音）
function HoldCall() {
	try {
		ctrl.HoldCall();
	}
	catch (e) {
		alert(e.message);
	}
}

//取保持(取回保持的电话)
function RetrieveCall(){
	try {
		ctrl.RetrieveCall();
	}
	catch (e) {
		alert(e.message);
	}
}

//挂机(满意度调查)
function ReleaseCallEx(){
	try{
		var call = ctrl.ActiveCallInfo;
		if(call!=null && call.CallDirection == 1){
			ctrl.SetTransferData(ctrl.AgentId);	// 写入座席工号
			ctrl.TransferToIVR("1234510000", false);//评价
		}else{
			ctrl.ReleaseCall();}
	}catch(e){
		alert(e.message);
	}
}

//挂机
function ReleaseCall(){
	try {
		ctrl.ReleaseCall();
		//alert("guaduan");
	}
	catch (e) {
		alert(e.message);
	}
}

//初始化转接操作
function InitialTransfer(number) {
	try {
		var caller = "12345" + GetPhoneNumber(ctrl.ActiveCallInfo);


		ctrl.InitialTransferEx(caller, "9"+number);
		//alert("打出电话"+number);
	}
	catch (e) {
		alert(e.message);
	}
}
//疫情处
function TransferToQueue(number) {
	try {
		ctrl.TransferToQueue(number);
	}
	catch (e) {
		alert(e.message);
	}
}


function InitialTransferold() {
	try {
		var str = textNumber2.value;
		if (str == null) {
			alert("请输入电话号码");
			return;
		}

		ctrl.InitialTransfer(str);
	}
	catch (e) {
		alert(e.message);
	}
}

//初始化三方通话
function InitialConference(number) {
	try {
		ctrl.InitialConference("9"+number);
		//alert("打出电话"+number);
	}
	catch (e) {
		alert(e.message);
	}
}
function InitialConferenceold() {
	try {
		var str = textNumber2.value;
		if (str == null) {
			alert("请输入电话号码");
			return;
		}

		ctrl.InitialConference("9"+str);
	}
	catch (e) {
		alert(e.message);
	}
}

//取消转接(挂断第三方的呼叫，并取回保持的呼叫。)
function CancelTransfer(){
	try {
		ctrl.CancelTransfer();
		updateAgentStatus();

		return 0;
	}
	catch (e) {
		alert(e.message);
		return -1
	}
}

//完成转接
function CompleteTransfer(){
	try {
		ctrl.CompleteTransfer();
		updateAgentStatus();
		return 0;
	}
	catch (e) {
		alert(e.message);
		return -1;
	}
}



//取消三方通话
function CancelConference(){
	try {
		ctrl.CancelConference();
		updateAgentStatus();
		return 0;
	}
	catch (e) {
		alert(e.message);
		return -1;
	}
}

//完成三方通话
function CompleteConference(){
	try {
		ctrl.CompleteConference();
		updateAgentStatus();
		return 0;
	}
	catch (e) {
		alert(e.message);
		return -1;
	}
}

//强制坐席示闲
function ForceReady() {
	try {
		var str = agentId.value;
		if (str == null) {
			alert("请输入坐席工号");
			return;
		}
		var str2 = extensionNum .value;
		if (str2 == null) {
			alert("请输入坐席工单号");
			return;
		}

		ctrl.ForceReady(str,str2);
	}
	catch (e) {
		alert(e.message);
	}
}

//强制坐席示忙
function ForceNotReady() {
	try {
		var str = agentId.value;
		if (str == null) {
			alert("请输入坐席工号");
			return;
		}
		var str2 = extensionNum .value;
		if (str2 == null) {
			alert("请输入坐席工单号");
			return;
		}

		ctrl.ForceNotReady(str,str2);
	}
	catch (e) {
		alert(e.message);
	}
}

//强制坐席签出
function ForceLogout() {
	try {
		var str = agentId.value;
		if (str == null) {
			alert("请输入坐席工号");
			return;
		}
		var str2 = extensionNum .value;
		if (str2 == null) {
			alert("请输入坐席工单号");
			return;
		}

		ctrl.ForceLogout(str,str2);
	}
	catch (e) {
		alert(e.message);
	}
}

//强制挂断
function ForceRelease() {
	try {
		var str2 = extensionNum .value;
		if (str2 == null) {
			alert("请输入坐席工单号");
			return;
		}

		ctrl.ForceRelease(str2);
	}
	catch (e) {
		alert(e.message);
	}
}


//更新签入签出后的按钮状态
function updateLoginStatus() {
	var state = ctrl.IsLoggedIn;//IsLoggedIn:只读属性，获取座席是否已签入。。
	if(state)
		//cti_qianru();
		;
	else
		//cti_qianchu();
		;
}

//更新座席状态显示
function updateAgentStatus(){
	var map = ["未登录", "示闲", "示忙", "振铃中", "正在呼叫", "通话中", "话后处理"];
	var state = ctrl.AgentStatus;//AgentState:只读属性，获取座席当前状态。
	window.document.getElementById("ctiStatus").innerText =map[state];

	switch(state) {
		case 0://未登录(ok)
			cti_state0weidl(); //除登录按钮外屏蔽所有功能
			break;
		case 1://空闲(ok)
			cti_state1kongxian(); // Enable：注销登录、示忙、呼叫 Disable: 登录、接听、示闲、三方、转接
			break;
		case 2://忙碌(ok)
			cti_state2manglu(); // Enable： 注销登录、示闲、呼叫 Disable: 登录、接听、示忙、三方、转接
			break;
		case 3://振铃
			cti_state3zhenlin(); // Enable: 接听 Disable: 登录、注销登录、示忙、示闲、三方、转接、呼叫、挂机
			break;
		case 4://正在呼叫
			cti_guaduan();//显示外呼的挂断按钮 //  Enable:  挂机 Disable: 登录、注销登录、接听、示忙、示闲、三方、转接、呼叫
			break;
		case 5://通话中(Qx)
			var callDirection = 0; //0=未知 1=呼入 2=呼出
			if(ctrl.ConferenceState == 0) { //不是三方通话
				if(ctrl.ActiveCallInfo != null){
					callDirection = ctrl.ActiveCallInfo.CallDirection;
				}
				/*
				if(callDirection==0 && isOpenRcd==false){
					//硬话机上按下接听按钮,且没有打开录入窗口
					NewTelWinOpen(ctrl.ActiveCallInfo.CallId,ctrl.ActiveCallInfo.CallerNum,"-1");
				}
*/
			}
			cti_state5tonghua(callDirection); // Enable: 挂机、三方、转接 Disable: 登录、注销登录、接听、示忙、示闲、呼叫
			break;
		case 6://话后
			cti_state6huahou(); // Enable: 注销登录、示闲 Disable：登录、示忙、接听、三方、转接、挂机
			break;

		default:
			break;
	}
}

//--------------------CTI Base-------end-----------

//--------------------call CTI-------begin---------
var jsTimer;
//初始化接续控件
function InitialCtiOcx(fpWNo,fpTpye,fpTNo,fpEqu) {

	try {

		ctrl.PrimaryCTIServerIP = "10.190.202.204";	//呼叫中心主 CTI 服务器IP地址
		ctrl.BackupCTIServerIP = "10.190.202.205";	//后备CTI 服务器IP地址

		ctrl.AgentId = fpWNo;//"8012";						//座席工号
		ctrl.ExtensionNum =fpTNo;// "60012";				//座席分机号
		ctrl.Timeout = 30000;						//超时时长，单位为毫秒

		if(parseInt(fpEqu)>0)
			ctrl.UseWebVoip = false;
		else
			ctrl.UseWebVoip = true;  //（新增属性）使用内置软电话

		ctrl.WebVoipServerIP = "10.190.202.200"; 	// （新增属性）内置软电话服务器地址
		ctrl.WebVoipServerPort = 5060; 				// （新增属性）内置软电话服务器端口
		ctrl.WebVoipBackupServerIP = ""; 			// （新增属性）内置软电话备用服务器地址
		ctrl.WebVoipBackupServerPort = 5060; 		// （新增属性）内置软电话备用服务器端口
		ctrl.WebVoipAccount = fpTNo;//"60012";				// （新增属性）内置软电话注册账号
		ctrl.WebVoipPassword = "cd12345";			// （新增属性）内置软电话注册密码

		ctrl.Initial();

		this.updateAgentStatus();//显示登录状态。130914 如果没有登录成功，显示“undefined”

		timer = window.setInterval("updateAgentStatusTime()", 100);//timer:全局变量
	}
	catch (e) {
		alert(e.message);
	}
}
//--------------------call CTI-------end-----------
